/*
 * File:   Example3.java
 * Author: Oleg S. Estekhin
 */
package dht.emulator.example;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.concurrent.atomic.AtomicInteger;

import dht.emulator.DefaultNode;
import dht.emulator.Identifier;
import dht.emulator.Node;
import dht.emulator.filters.GlobalMessageCounter;
import dht.emulator.filters.MessageCounter;

public class Example7
{

    public static void main(String[] args)
    {
        Random random;
        if (false)
        {
            random = new Random(0L);
        }
        else
        {
            random = new Random();
        }

        int ID_LEN = 4;
        AtomicInteger counter = new AtomicInteger();
        int value = 0;
        List<Node> nodes = new ArrayList<Node>();
        int size = 10;
        Node previous = null;
        for (int i = 0; i < size; i++)
        {
            List<Node> knownNodes = new ArrayList<Node>();
            if (previous != null)
            {
                knownNodes.add(previous);
            }

            Node node = new GlobalMessageCounter(
                    new MessageCounter(new DefaultNode(Identifier.randomIdentifier(ID_LEN, random), knownNodes)),
                    counter);
            counter.set(0);
            node.init();
            System.out.println(node + " global = " + counter.get());
            node.putValue(Identifier.randomIdentifier(ID_LEN, random), "Value" + value);
            value++;

            nodes.add(node);
            previous = node;
            // System.out.println(i+" "+ node);
        }
/*        for (int i=size-1; i>0; i--)
        {
            nodes.get(0).getQuality(nodes.get(i));
        }*/
        System.out.println();
        for (Node node : nodes)
        {
            System.out.println(node);
        }
    }

}